package com.yizisu.library.ad

import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleOwner
import com.weilele.mvvm.base.helper.ILifecycleObserver
import com.yizisu.library.ad.impl.applovin.ApplovinImpl
import com.yizisu.library.ad.impl.ironsource.IronSourceImpl

interface IAd : ILifecycleObserver {
    companion object {

        operator fun invoke(appCompatActivity: AppCompatActivity): IAd {
            return ApplovinImpl.getInstance(appCompatActivity)
        }

        fun initSdk(appCompatActivity: AppCompatActivity, uid: String?, block: Function0<Unit>) {
            IronSourceImpl.getInstance(appCompatActivity, uid)
            ApplovinImpl.initSdk(appCompatActivity, block)
        }
    }

    /**
     * 显示广告，如果正在加载，则等待一定时间,0表示不等待
     */
    fun showVideoAd(
        wait: Long = 0,
        life: LifecycleOwner? = null,
        rewardListener: Function1<IAdRewardStatus, Unit>
    ): Boolean

    /**
     * 取消等待广告加载
     */
    fun cancelWaitVideoAd()

    /**
     * 显示积分墙
     */
    fun showOfferWall(): Boolean

    /**
     * 刷新积分墙奖励
     */
    fun getOfferWallCredits()

    /**
     * 设置积分墙的监听
     */
    fun setOnOfferWallListener(
        listener: ((
            credits: Int/*用户可领取的积分*/,
            totalCredits: Int/*曾经获得的总积分*/,
            totalCreditsFlag: Boolean/*提供数据是否准确*/
        ) -> Boolean)?
    )
}